var util = require('../../utils/util.js')
var request = require('../../utils/https.js')
var uri = 'orderInfo/orderInfo'
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role: wx.getStorageSync('userType'),
    carts: [],
    addressList:'',
    status:0,
    message:'',
    payTime:'',
    express:'',
    expressNo:'',
    expressTime:'',
    finishTime:'',
    recoveryNum:'',
    recoveryTime:'',
    returnNum:'',
    returuTime: '',
  },
  getTotalPrice() {
    let carts = this.data.carts;                 // 获取购物车列表
    let count = 0;                               // 获取购物车产品数量
    let total = 0;
    for (let i = 0; i < carts.length; i++) {         // 循环列表得到每个数据
      if (carts[i].selected) {                     // 判断选中才会计算价格
        total += carts[i].num * carts[i].price;   // 所有价格加起来
        count += carts[i].num;                           // 所有数量加起来
      }
    }
    this.setData({                                // 最后赋值到data中渲染到页面
      carts: carts,
      totalPrice: total.toFixed(2),
      totalCount: count
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      status:4,
      message:'',
      express:'韵达快递',
      expressNo:'58257633433',
      payTime:'2018-07-14 10:20:32',
      expressTime: '2018-07-14 10:20:32',
      finishTime: '2018-07-14 10:20:32',
      recoveryNum: '5箱 300个瓶',
      recoveryTime: '2018-07-14 10:20:32',
      returnNum: '51瓶',
      returuTime: '2018-07-14 10:20:32',
      carts: [
        {
          id: 1,
          title: '汇源果肉饮料+桃+猕猴桃 2500ml*3瓶餐桌大瓶果汁套装',
          image: '../../../images/g1.png',
          num: 4,
          price: 32.9,
          selected: true
        },
        {
          id: 2,
          title: '汇源果肉饮料+桃+猕猴桃 2500ml*3瓶餐桌大瓶果汁套装1',
          image: '../../../images/g2.png',
          num: 1,
          price: 32.9,
          selected: true
        }
      ],
      addressList: {
        "name": "小明",
        "tel": "18990312856",
        "address": "成都市人民南路255号"
      },
    })
    this.getTotalPrice();
  }
})